package com.project.user.service.impl;

import java.util.List;

import com.project.common.utils.TimeUuidUtil;
import com.project.user.domain.UserOrder;
import com.project.user.domain.UserOrderRemark;
import com.project.user.mapper.UserOrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.project.user.mapper.UserGoodsRemarkMapper;
import com.project.user.domain.UserGoodsRemark;
import com.project.user.service.IUserGoodsRemarkService;
import com.project.common.utils.str.Convert;
import org.springframework.transaction.annotation.Transactional;

/**
 * 餐饮评价 服务层实现
 *
 * @author administrator
 */
@Service
public class UserGoodsRemarkServiceImpl implements IUserGoodsRemarkService {
    @Autowired
    private UserGoodsRemarkMapper userGoodsRemarkMapper;

    @Autowired
    private UserOrderMapper userOrderMapper;


    /**
     * 查询餐饮评价列表
     *
     * @param userGoodsRemark 餐饮评价信息
     * @return 餐饮评价集合
     */
    @Override
    public List<UserGoodsRemark> selectUserGoodsRemarkList(UserGoodsRemark userGoodsRemark) {
        return userGoodsRemarkMapper.selectUserGoodsRemarkList(userGoodsRemark);
    }

    @Override
    public List<UserOrderRemark> selectOrderRemarkForUser(Long userId) {
        return userGoodsRemarkMapper.selectOrderRemarkForUser(userId);
    }

    /**
     * 新增餐饮评价
     *
     * @param userGoodsRemark 餐饮评价信息
     * @return 结果
     */
    @Override
    @Transactional
    public int insertUserGoodsRemark(UserGoodsRemark[] userGoodsRemark) {
        userOrderMapper.updateUserOrder(new UserOrder(userGoodsRemark[0].getOrderId(), 3));
        for (UserGoodsRemark remark : userGoodsRemark) {
            remark.setId(TimeUuidUtil.get16UUID());
            userGoodsRemarkMapper.insertUserGoodsRemark(remark);
        }
        return userGoodsRemark.length;
    }

    /**
     * 删除餐饮评价对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteUserGoodsRemarkByIds(String ids) {
        return userGoodsRemarkMapper.deleteUserGoodsRemarkByIds(Convert.toStrArray(ids));
    }

    /**
     * 统计餐饮评论数量
     *
     * @param goodsId
     * @return
     */
    @Override
    public int countGoodsRemark(Long goodsId) {
        return userGoodsRemarkMapper.countGoodsRemark(goodsId);
    }

}
